﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DECOR.DL.DALC.SAPC.Proxy;
using DECOR.BL.BE;
using System.Data;

namespace DECOR.DL.DALC.SAPC
{
    public class CondicionPagoDALC : ICondicionPagoDALC
    {
        
       public static CondicionPagoDALC Instance() {
            if (_instance == null)
            {
                lock (typeof(CondicionPagoDALC))
                {
                    if (_instance == null)
                    {
                        _instance = new CondicionPagoDALC();
                    }
                }
            }
            return _instance;
        }

        private CondicionPagoDALC() { }
        private static volatile CondicionPagoDALC _instance = null;


        #region ICondicionPagoDALC Members

        public List<GenericBE> listar(string pID)
        {
            CondicionesPagoProxy proxy = new CondicionesPagoProxy();
            proxy.Connection = DALC.getConnection;
            if (!proxy.Connection.IsOpen) { proxy.Connection.Open(); }
            /* llamando a la función */
            //string ex_result = "";
            T052UTable tblResult = new T052UTable();
            proxy.Zweb_Lista_Condicionespago(pID, ref tblResult);
            SAP.Connector.SAPConnectionPool.ReturnConnection(proxy.Connection);
            proxy.Connection = null;
            /* Manejando el retorno */
            DataTable dt = tblResult.ToADODataTable();

            List<GenericBE> listaResult = new List<GenericBE>();
            foreach (DataRow dr in dt.Rows)
            {
                GenericBE obj = new GenericBE();
                obj.Codigo = dr["ZTERM"].ToString();
                obj.Descripcion = dr["ZTERM"].ToString() + " :: " + dr["TEXT1"].ToString();
                listaResult.Add(obj);
            }
            return listaResult;
        }

        #endregion
    }
}
